//
//  YQTimestamp.swift
//  yq微信
//
//  Created by 杨庆 on 2018/1/13.
//  Copyright © 2018年 yq. All rights reserved.
//

import Foundation
import UIKit

extension String {
    static func yq_convastionTimeStr(time:Double)->String {
    
        // 获取当前日历
        let calendar = NSCalendar.current
        // 当前时间组建
        let date:Date = Date()
        let components = calendar.dateComponents([.year,.month,.day], from: date)
        
        // 当前年月日
        let currentyear = components.year
        let currentmonth = components.month
        let currentday = components.day
        
        // 获取发送时间
        let sendDate = Date.init(timeIntervalSince1970: time/1000)
        let sendComponents = calendar.dateComponents([.year,.month,.day], from: sendDate)
        
        let sendYear = sendComponents.year
        let sendMonth = sendComponents.month
        let sendDay = sendComponents.day
    
        
        let fmt:DateFormatter = DateFormatter()
        
        if currentyear == sendYear && currentmonth == sendMonth && currentday == sendDay {
            fmt.dateFormat = "今天:HH:mm"
        }else if (currentyear == sendYear && currentmonth == sendMonth && currentday!+1 == sendDay ){
            fmt.dateFormat = "昨天:HH:mm"
        }else {
            fmt.dateFormat = "MM:dd"
        }
        
        return fmt.string(from: sendDate)
    }
}
